package com.xxl.job.executor.service.jobhandler;


import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class LogJob {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @XxlJob("logDateHandler")
    public void logDate(String params){
        System.out.println("获取参数:"+params);
        System.out.println("上下文获取参数:"+XxlJobHelper.getJobParam());
        XxlJobHelper.log(new Date().toString());
    }


    @XxlJob("logJdbcQuery")
    public void logJdbcQuery(String params){
        Integer logCount =  jdbcTemplate.queryForObject("select count(*) from xxl_job_log",Integer.class);
        XxlJobHelper.log("查询日志总数是:{}",logCount);
    }


    @XxlJob("misfireStrategy")
    public void misfireStrategy(){
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
    }
}
